<template>
  <el-card class="main-card">
    <com-area title="查询条件">
      <template v-slot:main>
        <com-search
          ref="neuSearch"
          :config="searchParams.config"
          :formData="searchParams.formData"
          :buttons="searchParams.button"
          :searchLayoutParam="searchParams.searchLayoutParam"
        />
      </template>
    </com-area>
    <com-area
      title="列表"
      :loading="loading"
      :loading-size="1"
      :auto="true"
    >
      <template v-slot:toolbar>
        <com-toolBar :btnList="toolBarParams.btnList" />
      </template>
      <template v-slot:main>
        <com-table
          ref="table"
          :data="tableParams.tableData"
          :options="tableParams.options"
          :export="null"
          @search="search"
        />
      </template>
    </com-area>
  </el-card>
</template>

<script>
import { listPerson, getPersons, addPerson, updatePerson } from '@/api/business/Person'
import searchParams from "./SearchParams";
import tableParams from "./TableParams";
import toolBarParams from "./ToolBarParams";

export default {
  created() {
    this.search();
  },
  data: function() {
    return {
      searchParams: searchParams(this),
      tableParams: tableParams(this),
      toolBarParams: toolBarParams(this),
      loading: true,
      keywords: null,
      currentPage: 1,
      pageSize: 10,
      addOrEditModal: false,
      addOrEditType: "",
      personForm: {
        name: "",
        medical: "",
        phone: "",
        department: "",
        email: "",
        specialty: ""
      }
    };
  },
  methods: {
    search(reqParams) {
      console.log(reqParams);
      this.loading = true;
      listPerson({
          page: reqParams ? reqParams.currentPage : this.currentPage,
          limit: reqParams ? reqParams.pageSize : this.pageSize,
        personName: reqParams ? reqParams.personName : "",
          queryUnit: reqParams ? reqParams.queryUnit : ""
        })
        .then(({ data }) => {
          this.tableParams.options.currentPage = reqParams ? reqParams.currentPage : this.currentPage;
          this.tableParams.options.pageSize = reqParams ? reqParams.pageSize : this.pageSize;
          this.tableParams.options.total = data.total;
          this.tableParams.tableData = data.list;
          this.loading = false;
        });
    },
    openAddOrEditModel(row, type) {
      if (type === "add"){
        this.$router.push({ name: 'Add', params: { type: "add" }});
      }else if (type === "edit"){
        this.$router.push({ name: 'Edit', params: { type: "edit", data: row }});
      }else if (type === "check"){
        this.$router.push({ name: 'Check', params: { type: "check", data: row }});
      }
    }
  }
};
</script>
<style scoped></style>
